﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GiaiHePhuongTrinh
{
    public partial class GiaiPTBac1 : Form
    {
        double soA, soB, KQ;
        void xoa()
        {
            soA = 0;
            soB = 0;
            KQ = 0;
            
            txtHSa.Text = "";
            txtHSb.Text = "";
            txtKQ.Text = "";
        }
        public GiaiPTBac1()
        {
            InitializeComponent();
            xoa();
        }

        private void btnGiai_Click(object sender, EventArgs e)
        {
            soA = double.Parse(txtHSa.Text);
            soB = double.Parse(txtHSb.Text);
            if (soA == 0)
            {
                txtKQ.Text = "vo nghiem";                
            }
            else
            {
                KQ = (-soB) / soA;
                txtKQ.Text = KQ.ToString();
            }
            
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            xoa();
        }

        private void txt_TextChanged(object sender, EventArgs e)
        {
            TextBox A = (TextBox)sender;
            double a;
            try
            {
                if (A.Text == "-")
                {
                    return;
                }
                a = double.Parse(A.Text);
            }
            catch (Exception)
            {
                A.Text = "";
            }
        }
    }
}
